package jphysics;

import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;

/**
 * @author KaLeonis
 */
public class DLine extends Group {

	private Circle c1;
	private Circle c2;
	private Line line;
	
	public DLine() {
		c1 = new Circle(120, 170, 5);
		c2 = new Circle(150, 190, 5);
		line = new Line(c1.getCenterX(), c1.getCenterY(), c2.getCenterX(), c2.getCenterY());
		
		c1.setFill(Color.BLUE);
		c2.setFill(Color.BLUE);
		line.setFill(Color.GREEN);
		
		c1.setOnMouseDragged(new EventHandler<MouseEvent>() {
			public void handle(MouseEvent t) {
				c1_onMouseDragged(t);
			}
		});
		
		c2.setOnMouseDragged(new EventHandler<MouseEvent>() {
			public void handle(MouseEvent t) {
				c2_onMouseDragged(t);
			}
		});
		
		getChildren().add(c1);
        getChildren().add(c2);
		getChildren().add(line);
	}
	
	private void c1_onMouseDragged(MouseEvent t) {
		c1.setCenterX(t.getX());
		c1.setCenterY(t.getY());
		line.setStartX(t.getX());
		line.setStartY(t.getY());
	}
	
	private void c2_onMouseDragged(MouseEvent t) {
		c2.setCenterX(t.getX());
		c2.setCenterY(t.getY());
		line.setEndX(t.getX());
		line.setEndY(t.getY());
	}
}
